package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.PigTypeDAO;
import cn.edu.scau.cmi.hombio.dao.SaleTaskQualityDAO;
import cn.edu.scau.cmi.hombio.dao.TaskDAO;

import cn.edu.scau.cmi.hombio.domain.PigType;
import cn.edu.scau.cmi.hombio.domain.SaleTaskQuality;
import cn.edu.scau.cmi.hombio.domain.Task;

import cn.edu.scau.cmi.hombio.service.SaleTaskQualityService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for SaleTaskQuality entities
 * 
 */

@Controller("SaleTaskQualityRestController")

public class SaleTaskQualityRestController {

	/**
	 * DAO injected by Spring that manages PigType entities
	 * 
	 */
	@Autowired
	private PigTypeDAO pigTypeDAO;

	/**
	 * DAO injected by Spring that manages SaleTaskQuality entities
	 * 
	 */
	@Autowired
	private SaleTaskQualityDAO saleTaskQualityDAO;

	/**
	 * DAO injected by Spring that manages Task entities
	 * 
	 */
	@Autowired
	private TaskDAO taskDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for SaleTaskQuality entities
	 * 
	 */
	@Autowired
	private SaleTaskQualityService saleTaskQualityService;

	/**
	 * Get PigType entity by SaleTaskQuality
	 * 
	 */
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/pigType", method = RequestMethod.GET)
	@ResponseBody
	public PigType getSaleTaskQualityPigType(@PathVariable Integer saletaskquality_id) {
		return saleTaskQualityDAO.findSaleTaskQualityByPrimaryKey(saletaskquality_id).getPigType();
	}

	/**
	* Save an existing PigType entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/pigType", method = RequestMethod.PUT)
	@ResponseBody
	public PigType saveSaleTaskQualityPigType(@PathVariable Integer saletaskquality_id, @RequestBody PigType pigtype) {
		saleTaskQualityService.saveSaleTaskQualityPigType(saletaskquality_id, pigtype);
		return pigTypeDAO.findPigTypeByPrimaryKey(pigtype.getId());
	}

	/**
	* Delete an existing Task entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/task/{task_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSaleTaskQualityTask(@PathVariable Integer saletaskquality_id, @PathVariable Integer related_task_id) {
		saleTaskQualityService.deleteSaleTaskQualityTask(saletaskquality_id, related_task_id);
	}

	/**
	* Get Task entity by SaleTaskQuality
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/task", method = RequestMethod.GET)
	@ResponseBody
	public Task getSaleTaskQualityTask(@PathVariable Integer saletaskquality_id) {
		return saleTaskQualityDAO.findSaleTaskQualityByPrimaryKey(saletaskquality_id).getTask();
	}

	/**
	* View an existing PigType entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/pigType/{pigtype_id}", method = RequestMethod.GET)
	@ResponseBody
	public PigType loadSaleTaskQualityPigType(@PathVariable Integer saletaskquality_id, @PathVariable Integer related_pigtype_id) {
		PigType pigtype = pigTypeDAO.findPigTypeByPrimaryKey(related_pigtype_id, -1, -1);

		return pigtype;
	}

	/**
	* Delete an existing SaleTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSaleTaskQuality(@PathVariable Integer saletaskquality_id) {
		SaleTaskQuality saletaskquality = saleTaskQualityDAO.findSaleTaskQualityByPrimaryKey(saletaskquality_id);
		saleTaskQualityService.deleteSaleTaskQuality(saletaskquality);
	}

	/**
	* View an existing Task entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/task/{task_id}", method = RequestMethod.GET)
	@ResponseBody
	public Task loadSaleTaskQualityTask(@PathVariable Integer saletaskquality_id, @PathVariable Integer related_task_id) {
		Task task = taskDAO.findTaskByPrimaryKey(related_task_id, -1, -1);

		return task;
	}

	/**
	* Create a new PigType entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/pigType", method = RequestMethod.POST)
	@ResponseBody
	public PigType newSaleTaskQualityPigType(@PathVariable Integer saletaskquality_id, @RequestBody PigType pigtype) {
		saleTaskQualityService.saveSaleTaskQualityPigType(saletaskquality_id, pigtype);
		return pigTypeDAO.findPigTypeByPrimaryKey(pigtype.getId());
	}

	/**
	* Delete an existing PigType entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/pigType/{pigtype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteSaleTaskQualityPigType(@PathVariable Integer saletaskquality_id, @PathVariable Integer related_pigtype_id) {
		saleTaskQualityService.deleteSaleTaskQualityPigType(saletaskquality_id, related_pigtype_id);
	}

	/**
	* Create a new Task entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/task", method = RequestMethod.POST)
	@ResponseBody
	public Task newSaleTaskQualityTask(@PathVariable Integer saletaskquality_id, @RequestBody Task task) {
		saleTaskQualityService.saveSaleTaskQualityTask(saletaskquality_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Create a new SaleTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality", method = RequestMethod.POST)
	@ResponseBody
	public SaleTaskQuality newSaleTaskQuality(@RequestBody SaleTaskQuality saletaskquality) {
		saleTaskQualityService.saveSaleTaskQuality(saletaskquality);
		return saleTaskQualityDAO.findSaleTaskQualityByPrimaryKey(saletaskquality.getId());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Save an existing Task entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}/task", method = RequestMethod.PUT)
	@ResponseBody
	public Task saveSaleTaskQualityTask(@PathVariable Integer saletaskquality_id, @RequestBody Task task) {
		saleTaskQualityService.saveSaleTaskQualityTask(saletaskquality_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Show all SaleTaskQuality entities
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality", method = RequestMethod.GET)
	@ResponseBody
	public List<SaleTaskQuality> listSaleTaskQualitys() {
		return new java.util.ArrayList<SaleTaskQuality>(saleTaskQualityService.loadSaleTaskQualitys());
	}

	/**
	* Save an existing SaleTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality", method = RequestMethod.PUT)
	@ResponseBody
	public SaleTaskQuality saveSaleTaskQuality(@RequestBody SaleTaskQuality saletaskquality) {
		saleTaskQualityService.saveSaleTaskQuality(saletaskquality);
		return saleTaskQualityDAO.findSaleTaskQualityByPrimaryKey(saletaskquality.getId());
	}

	/**
	* Select an existing SaleTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/SaleTaskQuality/{saletaskquality_id}", method = RequestMethod.GET)
	@ResponseBody
	public SaleTaskQuality loadSaleTaskQuality(@PathVariable Integer saletaskquality_id) {
		return saleTaskQualityDAO.findSaleTaskQualityByPrimaryKey(saletaskquality_id);
	}
}